﻿@model HWmanagementClient.Models.StudentHomeworks
@{
    ViewBag.Title = "Index";
}
<script type="text/javascript">
    $(function () {
        $("#studentcourses").accordion();
    });

    function uploadHW(id) {
        $("input[type=submit]").button();
        $("#homewid").val(id);
        $("#dialog-form").dialog({
            modal: true,
            height: 400,
            width: 800,
            buttons: {
                Mégse: function () {
                    $(this).dialog("close");
                }
            }
        });
    }

    var markup = '<tr id="trashable">' +
                        '<td><strong>${title}</strong> (ID: ${id}, C: ${courseid}, U: ${userid})' +
                        '<br>${shortdesc}<br>Csatolt fájl: <a target="_blank" href="${fileurl}">${filename}</a><br>' +
                        '<em>Beadási határidő: <strong>${deadline2}</strong></em></td>' +
                        '<td>' +
                        '{{if isupload == true && grade == 0}}' +
                            '<a href="#" class="buttonclass" style="color: white;" onclick="uploadHW(${id});">Beadás</a> ' +
                        '{{else}}' +
                            'A feladat már nam adható be!' +
                        '{{/if}}' +
                        '</td>' +
                    '</tr>';

    function getHomework(id) {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/Student/GetHomeworks/" + id,
            dataType: "json",
            async: false
        })
			.done(function (msg) {
			    var hw = msg.Grades;
			    //alert(hw);
			    $("tr#trashable").remove();
			    $.template("hw_templ", markup);
			    $("#hwcontainer").before($.tmpl("hw_templ", hw));
			    //$.tmpl("hw_templ", hw).appendTo("#hwcontainer");
			    $("a.buttonclass").button();
			});
    }
</script>
<script id="hw_templ" type="text/x-jQuery-tmpl">
            
</script>
<h2>
    Házi feladataim</h2>
<table>
    <tr>
        <td valign="top">
            <div id="studentcourses">
                @foreach (var item in Model.Subjects)
                {
                    <h3>
                        @item.name (@item.neptun.ToUpper())</h3>
                    <div>
                        @foreach (var course in item.courses)
                        {
                            <a href="#" onclick="getHomework(@course.id);">[ @course.semester ]</a> 
                        }
                    </div>
                }
            </div>
        </td>
        <td>
            <table>
                <tbody>
                    <tr id="hwcontainer">
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
</table>
<div id="dialog-form" title="Házi feladat beadás" style="display: none;">
    @using (Html.BeginForm("Grades", "Student", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <div>
            <fieldset>
                <legend>A beadáshoz válaszd ki a feltölteni kívánt fájlt:</legend>
                <input type="file" name="file" />
                <input type="hidden" name="homew" value="none" id="homewid" />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <input type="submit" value="OK" />
            </fieldset>
        </div>
    }
</div>
